class Feed::Installed < Feed
  validates :order_item_id,
    :installation_id,
    :presence => true

  after_destroy do |feed|
    feed.installation.update_gathered_balance!
    feed.installation.update_installed_count!
    feed.installation.update_installed_cost!
  end

  def code
    ActiveSupport::StringInquirer.new('has_been_installed')
  end

  def short_desc
    desc = "#{installation.installer_full_name}于#{installation.installed_on}上门<b>完成安装</b>【#{
          installation.order_item.furniture_code}-#{installation.order_item.furniture_name} => #{
          installation.installed_count}件】 安装成本￥#{format("%.2f",installation.installed_cost)}"
    if installation.gathered_balance > 0
      desc += "  收款￥#{format("%.2f",installation.gathered_balance)}"
    end
    return desc
  end

  def remark
    installation.installed_remark
  end

  def related_one
    installation
  end
  
  def related_html_id
    "related_installation_#{installation.id}"
  end
  
  def related_type
    "related_installation"
  end
end
